package 题目集.dfs.洪水填充;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class 完全淹没的岛屿 {
    static int[][] dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
    static int[][] grid;
    static boolean[][] vis;
    static int[][] queue = new int[1001 * 1001][2];
    static int n;

    public static void main(String[] args) {
        Reader sc = new Reader();
        n = sc.nextInt();
        grid = new int[n][n];
        vis = new boolean[n][n];
        for (int i = 0; i < n; i++) {
            char[] chars = sc.nextLine().toCharArray();
            for (int j = 0; j < n; j++) {
                if (chars[j] == '#') {
                    grid[i][j] = 1;
                }
            }
        }
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid.length; j++) {
                if (grid[i][j] == 0) {
                    for (int[] dir : dirs) {
                        int x = i + dir[0];
                        int y = j + dir[1];
                        if (x >= 0 && x < n && y >= 0 && y < n && grid[x][y] == 1) {
                            grid[x][y] = 2;
                        }
                    }
                }
            }
        }
        int res = 0;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid.length; j++) {
                if (grid[i][j] == 2) {
                    if (bfs(i, j)) {
                        res++;
                    }
//                    flag = true;
//                    if (dfs(i, j)) {
//                        res++;
//                    }
                }
            }
        }
        System.out.println(res);
    }


    public static boolean bfs(int x, int y) {
        boolean flag = true;
        int h = 0, t = 0;
        queue[t][0] = x;
        queue[t++][1] = y;
        while (h < t) {
            int[] poll = queue[h++];
            for (int[] dir : dirs) {
                int nx = poll[0] + dir[0];
                int ny = poll[1] + dir[1];
                if (nx >= 0 && nx < n && ny >= 0 && ny < n && grid[nx][ny] != 0 && !vis[nx][ny]) {  //bfs的入队标记应该在这里做
                    if (grid[nx][ny] == 1) {
                        flag = false;
                    }
                    grid[nx][ny] = 0;
                    vis[nx][ny] = true;
                    queue[t][0] = nx;
                    queue[t++][1] = ny;
                }
            }
        }
        return flag;
    }

    /**
     * 是否能够完全淹没,并且把所有为2的点变为0
     * @param x
     * @param y
     * @return
     */
    static boolean flag = true;

    public static boolean dfs(int x, int y) {
        vis[x][y] = true;
        if (grid[x][y] == 2) {
            grid[x][y] = 0;
        } else {
            flag = false;
        }
        for (int[] dir : dirs) {
            int nx = x + dir[0];
            int ny = y + dir[1];
            if (nx >= 0 && nx < n && ny >= 0 && ny < n && grid[nx][ny] != 0 && !vis[nx][ny]) {
                dfs(nx, ny);
            }
        }
        return flag;
    }

    static class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public void clear() {
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }
}
